package myJs.user.mission.horizontalBoxplotResult

import com.softwaremill.quicklens._
import myJs.cps._
import myJs.tool.Tool._

import scala.collection.immutable.SeqMap

import japgolly.scalajs.react.vdom.all._
import japgolly.scalajs.react._
import japgolly.scalajs.react.React.Fragment
import japgolly.scalajs.react.util.EffectCatsEffect._
import myJs.myPkg.Hooks._
import cats.effect._
import myJs.Implicits._

/** Created by yz on 3/11/2020
 */
object FontCp {

  case class Props(
    basicData: Cp.plotO.FontData,
    basicDataChange: (Cp.plotO.FontData => Cp.plotO.FontData) => SyncIO[Unit]
  ){
    @inline def render: VdomElement = {
      Component(this)
    }
  }

  val Component = ScalaFnComponent[Props] { props =>

    object FTool {

      def strChange(f: PathLazyModify[Cp.plotO.FontData, String]) = (v: String) => {
        props.basicDataChange {
          f.setTo(v)
        }
      }

    }

    val basicData = props.basicData
    val fontFamilyMap = SeqMap("Times" -> "Times New Roman（serif）", "ArialMT" -> "Arial（sans）",
      "mono" -> "Courier（mono）", "SimSun" -> "宋体（SimSun）")

    Fragment(
      InputInlineCp.Props(
        label = "条形图坐标轴字体大小",
        name = "barAxisFont",
        labelWidth = 4,
        inputWidth = 8,
        value = basicData.barAxisFont,
        onChange = FTool.strChange(modifyLens[Cp.plotO.FontData](_.barAxisFont))
      ).render,
      InputInlineCp.Props(
        label = "条形图坐标轴标题大小",
        name = "barAxisTitleFont",
        labelWidth = 4,
        inputWidth = 8,
        value = basicData.barAxisTitleFont,
        onChange = FTool.strChange(modifyLens[Cp.plotO.FontData](_.barAxisTitleFont))
      ).render,
      InputInlineCp.Props(
        label = "散点图坐标轴字体大小",
        name = "scatterAxisFont",
        labelWidth = 4,
        inputWidth = 8,
        value = basicData.scatterAxisFont,
        onChange = FTool.strChange(modifyLens[Cp.plotO.FontData](_.scatterAxisFont))
      ).render,
      InputInlineCp.Props(
        label = "散点图坐标轴标题大小",
        name = "scatterAxisTitleFont",
        labelWidth = 4,
        inputWidth = 8,
        value = basicData.scatterAxisTitleFont,
        onChange = FTool.strChange(modifyLens[Cp.plotO.FontData](_.scatterAxisTitleFont))
      ).render,
      InputInlineCp.Props(
        label = "散点图标题大小",
        name = "scatterTitleFont",
        labelWidth = 4,
        inputWidth = 8,
        value = basicData.scatterTitleFont,
        onChange = FTool.strChange(modifyLens[Cp.plotO.FontData](_.scatterTitleFont))
      ).render,
      SelectInlineCp.Props(
        value = basicData.fontFamily,
        label = messages("font"),
        name = "fontFamily",
        optionMap = fontFamilyMap,
        labelWidth = 4,
        inputWidth = 8,
        onChange = FTool.strChange(modifyLens[Cp.plotO.FontData](_.fontFamily))
      ).render,
    )

  }

}
